<template>
  <a-drawer
    title="调剂"
    width=450
    placement="right"
    :closable="false"
    @close="onClose"
    :visible="transferringAdjustVisible"
    style="height: calc(100% - 55px);overflow: auto;padding-bottom: 53px;">
    <a-form :form='form'>
      <a-alert :showIcon="false" :message="'请选择 '+postParams.ksxm+' 要调剂的学校：'" banner />
      <a-row :gutter="48">
          <a-col :sm="{span:12}" :lg="{span:12}"  >
            <a-form-item label="调往省市">
              <a-select :allowClear="true" showSearch optionFilterProp="children"  v-decorator="['twssm']" @change='ssChange'>
                <a-select-option v-for="(i,j) in selectMenu.ss"  :key="j" :value="i.areaCode">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}"  >
            <a-form-item label="调剂单位">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-decorator="['twdwm']">
                <a-select-option v-for="i in selectMenu.dw" :key="i.id" :value="i.xxdm">{{ i.xxmc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
      </a-row>
    </a-form>
    <div class="drawer-bootom-button">
      <a-button style="margin-right: .8rem" @click="onClose">取消</a-button>
      <a-button @click="handleSubmit" type="primary" :loading="loading">保存</a-button>
    </div>
  </a-drawer>
</template>

<script>
// import moment from 'moment'
import { STable } from '~'
import { mapState } from 'vuex'

const formItemLayout = {
  labelCol: { span: 3 },
  wrapperCol: { span: 18 }
}

const selectArr = ['TYPE0126', 'TYPE0075', 'TYPE0125', 'TYPE0072']
export default {
  props: {
    transferringAdjustVisible: {
      default: false
    },
    info:{
      default:()=>({})
    }
  },
  components: {
    STable
  },
  data () {
    return {
      formItemLayout,
      loading: false,
      postParams: {
        twssm:'',
        twdwm:''
      },
      selectMenu: {
        ss: [] ,// 院系
        dw:[]
      }
    }
  },
  beforeCreate () {
    this.form = this.$form.createForm(this)
  },
  watch:{
    info(val){
      this.postParams = this.info;
      this.$api.base.areaList().then( res => {
      // this.selectMenu.ss = res.data
      this.$set(this.selectMenu,'ss', res.data)
    })
      // this.postParams.twssm = 410000
      // for(var item in this.postParams){
      //   if(item == 'id' || item == 'twdwm' || item == 'twssm'){
      //     this.form.getFieldsValue(item,{initialValue:this.info[item]})
      //   }
      // }
    }
  },
  computed: {
    ...mapState({
      systemInfo: state => state.app.systemInfo,
      TYPE0126: state => state.app['TYPE0126'] // 年级
    })
  },
  created () {
    this.initSelectMenu()
    
    selectArr.forEach(v => {
      this.$store.dispatch('app/setDictionary', v)
    })
  },
  methods: {
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll()
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          yx: res[0].data
        }
      })
    },
    reset () {
      this.data = []
    },
    // 选择院系
    yxChange (code) {
    },
    // 选择招生年度
    zsndChange () {

    },
    ssChange(code){
       this.$set(this.selectMenu,'dw',[])
       this.form.setFieldsValue({'twdwm':''})
      if(code){
        this.$api.base.getssSchool({xzqhsdm:code}).then( res => {
            if(res.data){
              this.$set(this.selectMenu,'dw',res.data)
            }
        })
      }
    },
    // 关闭
    onClose () {
      this.reset()
      this.$emit('close')
    },
    // 保存
    handleSubmit () {
      this.form.validateFields( (err,values) => {
        if(err){
          this.$message.error("请选择必填项")
        }else{
          var params = Object.assign({id:this.postParams.id},this.form.getFieldsValue())
          this.$api.recruitstat.candidateAdjustmentUpdate(params).then(res=>{
            this.reset()
            this.$emit('success', this.postParams)
          })
        }
      })
    },
    handleDelete (key) {
      const dataSource = [...this.data]
      this.data = dataSource.filter(item => item.key !== key)
    }
  }
}
</script>
